<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\cdc;

use app\enum\CommonEnum;
use app\enum\ServiceCostEnum;
use app\model\mongo\MongoInfoModel;
use app\model\mongo\MongoSyncModel;
use app\service\BaseService;
use app\service\cdc\append\KsPicAppendService;
use app\service\cdc\append\KsVideoAppendService;
use app\service\cdc\append\OePicAppendService;
use app\service\cdc\append\OeVideoAppendService;
use app\service\cdc\append\QqPicAppendService;
use app\service\cdc\append\QqVideoAppendService;

final class AppendService extends BaseService
{
    protected int $mediaId = 0;

    protected int $taskType = 0;

    private ?BaseService $service;

    public function __construct(int $mediaId = 0, int $taskType = 0)
    {
        $this->mediaId = $mediaId;
        $this->taskType = $taskType;
    }

    /**
     * 获取对象.
     * @return bool|KsPicAppendService|KsVideoAppendService|OePicAppendService|OeVideoAppendService|QqPicAppendService|QqVideoAppendService
     */
    public function getAppendObject()
    {
        if ($this->mediaId == CommonEnum::OE_MEDIA) {
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_VIDEO) {
                return $this->service = new OeVideoAppendService();
            }
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_PICTURE) {
                return $this->service = new OePicAppendService();
            }
        } elseif ($this->mediaId == CommonEnum::KS_MEDIA) {
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_VIDEO) {
                return $this->service = new KsVideoAppendService();
            }
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_PICTURE) {
                return $this->service = new KsPicAppendService();
            }
        } elseif ($this->mediaId == CommonEnum::QQ_MEDIA) {
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_VIDEO) {
                return $this->service = new QqVideoAppendService();
            }
            if ($this->taskType == ServiceCostEnum::TASK_TYPE_PICTURE) {
                return $this->service = new QqPicAppendService();
            }
        }

        return self::setError('未知媒体类型');
    }

    /**
     * 获取列表.
     * @param mixed $params 参数
     * @return mixed
     */
    public function getList(array $params = [])
    {
        return $this->service::getList($params);
    }

    /**
     * 运行修复.
     * @param MongoSyncModel $model 中间表模型
     */
    public function run(MongoSyncModel $model): bool
    {
        return $this->service->runStat($model);
    }

    /**
     * 添加中间表信息.
     * @param MongoInfoModel $model 素材模型
     * @return mixed
     */
    public function addLog(MongoInfoModel $model)
    {
        return $this->service::addLogByInfo($model);
    }

    public function getInfo(array $params = [])
    {
        return $this->service->getInfo($params);
    }

    public function delLog(array $params = [])
    {
        return $this->service->deleteLog($params);
    }
}
